package com.ys.controller.api.amazonorder;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bo.vo.R;
import com.ys.entity.amazonorder.TbBaseinfoDwmc;
import com.ys.service.amazonorder.TbBaseinfoDwmcService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/api/inter/tbBaseinfoDwmc")
public class ApiInterTbBaseinfoDwmcController {

//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);

	@Autowired
	private CommonApiService<TbBaseinfoDwmc> commonApiService;
	@Autowired
	private TbBaseinfoDwmcService tbBaseinfoDwmcService;
	
	/**
	 * 查询
	 */
	@RequiresPermissions("tbBaseinfoDwmc:view")
	@RequestMapping("/search")
	@ResponseBody
	public LayuiTableVoJA search(@ModelAttribute TbBaseinfoDwmc cond){
		return commonApiService.searchLay(cond);
	}

	/**
	 * 新增
	 */
	@PostMapping("/add")
	@ResponseBody
	public R add(@RequestParam Map<String, Object> params){

		return tbBaseinfoDwmcService.add(params);
	}

	/**
	 * 修改
	 */
	@RequiresPermissions("tbBaseinfoDwmc:edit")
	@PostMapping("/edit")
	@ResponseBody
	public R edit(@RequestParam Map<String, Object> params){
		return tbBaseinfoDwmcService.edit(params);
	}



	/**
	 * 删除
	 */

	@PostMapping("/deleteTrue")
	@ResponseBody
	public R deleteTrue(HttpServletRequest request, Long id) {

		try {
			tbBaseinfoDwmcService.deleteTbBaseinfoDwmc(id);
			return R.ok("删除成功!");
		}catch (Exception e){
			e.printStackTrace();
			return R.error("删除失败，请稍后重试！");
		}

	}

	/**
	 * 单位名称-弹出框信息查询
	 */
	@RequestMapping("/searchByModelSelector")
	@ResponseBody
	public LayuiTableVoJA searchByModelSelector(@ModelAttribute TbBaseinfoDwmc cond){
		try {
			cond.setOrderby("A.CreateTime ASC");
			LayuiTableVoJA tableVoJA = commonApiService.searchLay(cond);
			return tableVoJA;
		}catch (Exception e){
			LayuiTableVoJA tableVoJA = new LayuiTableVoJA();
			tableVoJA.setCode(1);
			tableVoJA.setMsg("查询出错，请稍后重试！");
			return tableVoJA;
		}
	}
	/**
	 * 弹出框调用
	 */
	@RequiresPermissions("tbBaseinfoDwmc:view")
	@RequestMapping("/searchForModal")
	@ResponseBody
	public LayuiTableVoJA searchForModal(@ModelAttribute TbBaseinfoDwmc cond) {

		cond.setStatus(1);

		return commonApiService.searchLay(cond);
	}
}
